package com.example.uberorganizer;

import java.util.GregorianCalendar;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class CalendarAdapterBlack extends CalendarAdapter {
	
	public CalendarAdapterBlack(Context c, GregorianCalendar monthCalendar)
	{
		super(c, monthCalendar);
	}
	
	 // create a new view for each item referenced by the Adapter 
	@Override
	 public View getView(int position, View convertView, ViewGroup parent) {  
	  View v = convertView;  
	  TextView dayView;  
	  if (convertView == null) { // if it's not recycled, initialize some  
	         // attributes  
	   LayoutInflater vi = (LayoutInflater) mContext  
	     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
	   v = vi.inflate(R.layout.calendar_item_black, null);  
	  
	  }  
	  dayView = (TextView) v.findViewById(R.id.date);  
	  // separates daystring into parts.  
	  String[] separatedTime = dayString.get(position).split("-");  
	  // taking last part of date. ie; 2 from 2012-12-02  
	  String gridvalue = separatedTime[2].replaceFirst("^0*", "");  
	  // checking whether the day is in current month or not.  
	  if ((Integer.parseInt(gridvalue) > 1) && (position < firstDay)) {  
	   // setting offdays to white color.  
	   dayView.setTextColor(Color.DKGRAY);  
	   dayView.setBackgroundColor(Color.TRANSPARENT);
	   dayView.setBackground(null);
	   dayView.setClickable(false);  
	   dayView.setFocusable(false);  
	  } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {  
	   dayView.setTextColor(Color.DKGRAY);
	   dayView.setBackgroundColor(Color.TRANSPARENT);
	   dayView.setBackground(null);
	   dayView.setClickable(false);  
	   dayView.setFocusable(false);  
	  } else {  
	   // setting curent month's days in blue color.  
	   dayView.setTextColor(Color.WHITE);
	   dayView.setBackground(null);
	  }  
	  
	  if (dayString.get(position).equals(curentDateString)) {  
	   setSelected(v);  
	   previousView = v;  
	  } else {  
	   v.setBackgroundResource(R.drawable.list_item_background_black);  
	  }  
	  dayView.setText(gridvalue);  
	  
	  // create date string for comparison  
	  String date = dayString.get(position);  
	  
	  if (date.length() == 1) {  
	   date = "0" + date;  
	  }  
	  String monthStr = "" + (month.get(GregorianCalendar.MONTH) + 1);  
	  if (monthStr.length() == 1) {  
	   monthStr = "0" + monthStr;  
	  }  
	  
	  // show icon if date is not empty and it exists in the items array  
	  ImageView iw = (ImageView) v.findViewById(R.id.date_icon);  
	  if (date.length() > 0 && items != null && items.contains(date)) {  
	   iw.setVisibility(View.VISIBLE);  
	  } else {  
	   iw.setVisibility(View.INVISIBLE);  
	  }  
	  return v;  
	 }  
	
	@Override
	 public View setSelected(View view) {  
		  if (previousView != null) {  
		   previousView.setBackgroundResource(R.drawable.list_item_background_black);
		  }  
		  previousView = view;  
		  view.setBackgroundResource(R.drawable.calendar_cel_selectl_fs);
		  return view;  
		 } 

}
